<template>
    <div class="right">
        <div class="header">会员中心-每日一练</div>
        <div class="content" v-if="!lianxishow && !shengjishow">
            <div class="title">{{ title }}</div>
            <div class="mes">
                已练习{{ correctNum }}题，完成{{ upgradeNum }}%
            </div>
            <div class="progress">
                <el-progress :percentage="upgradeNum" :stroke-width="10" :color="'red'">
                </el-progress>
            </div>
            <div class="buttons">
                <div class="shengji" @click="shengjiClick">我要升级</div>
                <div class="yuilian" @click="lianxiClick">每日一练</div>
            </div>
        </div>
        <lianxi v-if="lianxishow" @doClose="close"></lianxi>
        <shegnji v-if="shengjishow" @doClose="close"></shegnji>
    </div>
</template>
<script setup lang="ts">
import lianxi from './lianxi.vue';
import shegnji from './shegnji.vue';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
import { hasQuestion, getPracticeNum,hasUpgradeQuestion } from '@/api/index'
const loading = ref(false)
const title = ref('')
const correctNum = ref(0)
const upgradeNum = ref(0)
const lianxishow = ref(false)
const shengjishow = ref(false)

const getList = async () => {
    loading.value = true
    const res = await hasQuestion()
    if (res.code == 200) {
        title.value = '今天还没有练习，开始吧。'
    } else {
        title.value = '今天已经练习了明天再来吧。'
    }
    const response = await getPracticeNum()
    correctNum.value = response.data.correctNum
    upgradeNum.value = Math.floor(correctNum.value / response.data.questionNum * 100)

    loading.value = false
}

const shengjiClick = async() => {
    const res = await hasUpgradeQuestion({})
    if (res.code == 200) {
        shengjishow.value = true
    } else {
        proxy?.$modal.msgWarning(res.msg)
    }
}
// 每日一练
const lianxiClick = async () => {
    const res = await hasQuestion()
    if (res.code == 200) {
        lianxishow.value = true
    } else {
        proxy?.$modal.msgWarning(res.msg)
    }
}
const close = () => {
    lianxishow.value = false
    shengjishow.value = false
}

onMounted(async () => {
    getList()
});
</script>
<style scoped lang="scss">
.right {
    width: calc(100% - 410px);
    height: 100%;

    .header {
        width: 100%;
        padding: 15px 0;
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 18px;
        color: #000000;
        border-bottom: 1px solid #E6E6E6;
    }

    .content {
        width: 100%;
        height: calc(100% - 55px);
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-content: flex-start;
        box-sizing: border-box;
        padding: 40px 0 0 0;

        .title {
            width: 100%;
            text-align: center;
            margin-top: 50px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 18px;
            color: #000000;
        }

        .mes {
            width: 100%;
            font-family: Adobe Heiti Std;
            font-weight: normal;
            font-size: 14px;
            color: #A5A5A5;
            text-align: center;
            margin-top: 20px;
        }

        .progress {
            width: 60%;
            margin-left: 20%;
            margin-top: 20px;
        }

        :deep(.el-progress__text) {
            display: none;
        }

        .buttons {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 60px;

            .shengji {
                width: 221px;
                height: 44px;
                background: #FF0000;
                border-radius: 11px 11px 11px 11px;
                text-align: center;
                line-height: 44px;
                font-family: Microsoft YaHei;
                font-weight: 400;
                font-size: 20px;
                color: #FFFFFF;
                cursor: pointer;
            }

            .yuilian {
                width: 221px;
                height: 44px;
                background: #22AFE5;
                border-radius: 11px 11px 11px 11px;
                text-align: center;
                line-height: 44px;
                font-family: Microsoft YaHei;
                font-weight: 400;
                font-size: 20px;
                color: #FFFFFF;
                margin-left: 30px;
                cursor: pointer;
            }
        }


    }
}
</style>